package com.boco.modules.fdoc.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.boco.common.persistence.Page;
import com.boco.modules.fdoc.dao.SigServicepackDao;
import com.boco.modules.fdoc.model.ServicepackDetailsEntity;
import com.boco.modules.fdoc.model.SigServicepackEntity;
import com.boco.modules.fdoc.service.SigServicepackService;
import com.boco.modules.fdoc.vo.ServicepackDetailsVo;
import com.boco.modules.fdoc.vo.SigServicepackVo;

@Service
public class SigServicepackServiceImpl implements SigServicepackService{
	
	@Resource
	SigServicepackDao sigServicepackDao;

	@Override
	public List<SigServicepackEntity> getAll() {
		return sigServicepackDao.findAllList(null);
	}

	@Override
	public List<SigServicepackVo> getAllDetails() {
		List<SigServicepackEntity> entities = sigServicepackDao.findAllList(null);	//获取所有服务包信息
		List<SigServicepackVo> vos = new ArrayList<SigServicepackVo>();
		
		for (SigServicepackEntity sigServicepackEntity : entities) {
			SigServicepackVo vo = new SigServicepackVo();
			//封装服务包基础信息
			vo.setId(sigServicepackEntity.getId());
			vo.setPackName(sigServicepackEntity.getPackName());
			vo.setPackPrice(sigServicepackEntity.getPackPrice());
			vo.setUserPay(sigServicepackEntity.getUserPay());
			vo.setOrgratio(sigServicepackEntity.getOrgratio());
			vo.setAdviceGroup(sigServicepackEntity.getAdviceGroup());
			vo.setTarget(sigServicepackEntity.getTarget());
			vo.setRemarks(sigServicepackEntity.getRemarks());
			vo.setDetails(sigServicepackDao.getServicepackDetail(sigServicepackEntity.getId()));
			vos.add(vo);
		}
		return vos;
	}
	@Override
	public Page<SigServicepackEntity> getSigSvsPackInfoList(Page<SigServicepackEntity> page,
			SigServicepackEntity entity) {
		entity.setPage(page);
		//1.查询签约服务包信息列表
		List<SigServicepackEntity> list = sigServicepackDao.findSvsPackList(entity);
		page.setList(list);
		return page;
	}

	@Override
	public int insertSvsPackInfo(SigServicepackEntity sigSvsPackEntity) {
		return sigServicepackDao.insertSvsPackInfo(sigSvsPackEntity);
	}

	@Override
	public Page<ServicepackDetailsVo> getServicePackDetailsLst(Page<ServicepackDetailsVo> page,
			int servicepackId) {
		List<ServicepackDetailsVo> list = sigServicepackDao.getServicepackDetail(servicepackId);
		page.setList(list);
		return page;
	}

	@Override
	public boolean isExistSigSvsPack(String packName) {
		SigServicepackVo servicepackVo=sigServicepackDao.getSigSvsPackByName(packName);
		if (servicepackVo!=null) {
			return true;
		}else {
			return false;
		}
		
	}

	@Override
	public SigServicepackVo getSigSvsPackByName(String packName) {
		SigServicepackVo servicepackVo=sigServicepackDao.getSigSvsPackByName(packName);
		return servicepackVo;
		}

	public List<ServicepackDetailsVo> getServicePackDetailsListNotPage(
			int servicepackId) {
		return sigServicepackDao.getServicepackDetail(servicepackId);
	}

	@Override
	public SigServicepackVo getSigSvsPackById(int id) {
		return sigServicepackDao.getSigSvsPackById(id);
	}

	@Override
	public int deleteSigSvsPack(int sigId) {
		return sigServicepackDao.deleteSigSvsPack(sigId);
	}

	@Override
	public int deleteSigSvsPackDtlRln(int sigId) {
		return sigServicepackDao.updateSigSvsPackDtlRln(sigId);
	}

	@Override
	public int deleteSigSvsPackDtlsRln(int sigId, int detailsId) {
		return sigServicepackDao.updateSigSvsPackDtlsRln(sigId, detailsId);
	}

	@Override
	public Page<ServicepackDetailsEntity> getUnSvsPackDetailsList(Page<ServicepackDetailsEntity> page,int sigId) {
		
		List<ServicepackDetailsEntity> list = sigServicepackDao.findUnSvsPackDetailsList(sigId);
		page.setList(list);
		return page;
	}

	@Override
	public Page<ServicepackDetailsEntity> getSvsPackDtlLst(Page<ServicepackDetailsEntity> page,
			ServicepackDetailsEntity entity) {
		entity.setPage(page);
		List<ServicepackDetailsEntity> list = sigServicepackDao.getSvspackDtlLst(entity);
		page.setList(list);
		return page;
	}


}
